package com.windea.study.kotlin.jvm.spam

import org.apache.http.*
import org.apache.http.client.methods.*
import org.apache.http.entity.*
import org.apache.http.impl.client.*
import org.junit.*

class Tests {
	fun test1() {
		val httpClient = HttpClientBuilder.create().build()
		val getRequest = RequestBuilder.get("123")
			.addParameter("a", "b")
			.build()
		val postRequest = RequestBuilder.post("123")
			.addHeader("a", "b").addParameter("a", "b").setEntity(StringEntity("""{"a":"b"}""", "UTF-8"))
			.build()
		val getResponse = httpClient.execute(getRequest)
		val postResponse = httpClient.execute(postRequest)
		println(getResponse)
		println(postResponse)
	}
	
	@Test
	fun testPixiv() {
		//需要代理
		val httpClient = HttpClientBuilder.create().setProxy(HttpHost("127.0.0.1", 19180, "http")).build()
		httpClient.execute(RequestBuilder.get("https://www.pixiv.net").build()).also { println(it.statusLine) }
	}
	
	@Test
	fun testBaidu() {
		val httpClient = HttpClientBuilder.create().build()
		httpClient.execute(RequestBuilder.get("https://baidu.com").build()).also { println(it.statusLine) }
	}
}
